package com.ruoyi.web.controller.community;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.community.domain.CommunityComments;
import com.ruoyi.community.service.ICommunityCommentsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 社区评论Controller
 *
 * @author ruoyi
 * @date 2024-07-21
 */
@Anonymous
@RestController
@RequestMapping("/community/comments")
public class CommunityCommentsController extends BaseController
{
    @Autowired
    private ICommunityCommentsService communityCommentsService;

    /**
     * 查询社区评论列表
     */
//    @PreAuthorize("@ss.hasPermi('community:comments:list')")
    @GetMapping("/list")
    public TableDataInfo list(CommunityComments communityComments)
    {
        startPage();
        List<CommunityComments> list = communityCommentsService.selectCommunityCommentsList(communityComments);
        return getDataTable(list);
    }

    /**
     * 导出社区评论列表
     */
//    @PreAuthorize("@ss.hasPermi('community:comments:export')")
    @Log(title = "社区评论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CommunityComments communityComments)
    {
        List<CommunityComments> list = communityCommentsService.selectCommunityCommentsList(communityComments);
        ExcelUtil<CommunityComments> util = new ExcelUtil<CommunityComments>(CommunityComments.class);
        util.exportExcel(response, list, "社区评论数据");
    }

    /**
     * 获取社区评论详细信息
     */
//    @PreAuthorize("@ss.hasPermi('community:comments:query')")
    @GetMapping(value = "/{commentsId}")
    public AjaxResult getInfo(@PathVariable("commentsId") Long commentsId)
    {
        return success(communityCommentsService.selectCommunityCommentsByCommentsId(commentsId));
    }

    /**
     * 新增社区评论
     */
//    @PreAuthorize("@ss.hasPermi('community:comments:add')")
    @Log(title = "社区评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CommunityComments communityComments)
    {
        return toAjax(communityCommentsService.insertCommunityComments(communityComments));
    }

    /**
     * 修改社区评论
     */
//    @PreAuthorize("@ss.hasPermi('community:comments:edit')")
    @Log(title = "社区评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CommunityComments communityComments)
    {
        return toAjax(communityCommentsService.updateCommunityComments(communityComments));
    }

    /**
     * 删除社区评论
     */
//    @PreAuthorize("@ss.hasPermi('community:comments:remove')")
    @Log(title = "社区评论", businessType = BusinessType.DELETE)
	@DeleteMapping("/{commentsIds}")
    public AjaxResult remove(@PathVariable Long[] commentsIds)
    {
        return toAjax(communityCommentsService.deleteCommunityCommentsByCommentsIds(commentsIds));
    }
}
